package top.lixunda.commerce.common.core.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import top.lixunda.commerce.common.core.controller.wrapper.BaseDataQuerySqlWrapper;
import top.lixunda.commerce.common.core.controller.wrapper.BaseDataUpdateSqlWrapper;
import top.lixunda.commerce.common.core.controller.wrapper.PageWrapper;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.commerce.common.core.controller.wrapper.EntityUpdateWrapper;

import java.util.List;
import java.util.Map;

/**
 * @author LiXunda
 * @version time:2019/10/11 20:17
 */
public interface IController<T> {

    /**
     * 统一添加前缀，防止与用户自定义实习冲突
     */
    String URL_PREFIX = "my_controller_base_";

    /*******增*************增*****************增****************增****************增*************增************增*******/
    @PostMapping(URL_PREFIX + "save")
    MessageObject<Boolean> save(@RequestBody T entity);

    @PostMapping(URL_PREFIX + "saveBatchBatchSize")
    MessageObject<Boolean> saveBatch(@RequestBody List<T> entityList,
                                     @RequestParam("batchSize") int batchSize);

    @PostMapping(URL_PREFIX + "saveBatch")
    MessageObject<Boolean> saveBatch(@RequestBody List<T> entityList);

    @PostMapping(URL_PREFIX + "saveOrUpdate")
    MessageObject<Boolean> saveOrUpdate(@RequestBody T entity);

    @PostMapping(URL_PREFIX + "saveOrUpdateWrapper")
    MessageObject<Boolean> saveOrUpdate(@RequestBody EntityUpdateWrapper<T> entityUpdateWrapper);

    @PostMapping(URL_PREFIX + "saveOrUpdateBatchBatchSize")
    MessageObject<Boolean> saveOrUpdateBatch(@RequestBody List<T> entityList,
                                             @RequestParam("batchSize") int batchSize);

    @PostMapping(URL_PREFIX + "saveOrUpdateBatch")
    MessageObject<Boolean> saveOrUpdateBatch(@RequestBody List<T> entityList);


    /*******删*************删*****************删****************删****************删*************删************删*******/
    @GetMapping(URL_PREFIX + "removeById")
    MessageObject<Boolean> removeById(@RequestParam("id") String id);

    @PostMapping(URL_PREFIX + "removeByMap")
    MessageObject<Boolean> removeByMap(@RequestBody Map<String, Object> columnMap);

    @PostMapping(URL_PREFIX + "remove")
    MessageObject<Boolean> remove(@RequestBody BaseDataUpdateSqlWrapper<T> queryWrapper);

    @PostMapping(URL_PREFIX + "removeByIds")
    MessageObject<Boolean> removeByIds(@RequestBody List<String> idList);


    /*******改*************改*****************改****************改****************改*************改************改*******/
    @PostMapping(URL_PREFIX + "updateById")
    MessageObject<Boolean> updateById(@RequestBody T entity);

    @PostMapping(URL_PREFIX + "updateEntity")
    MessageObject<Boolean> update(@RequestBody EntityUpdateWrapper<T> entityUpdateWrapper);

    @PostMapping(URL_PREFIX + "updateWrapper")
    MessageObject<Boolean> update(@RequestBody BaseDataUpdateSqlWrapper<T> updateWrapper);

    @PostMapping(URL_PREFIX + "updateBatchByIdBatchSize")
    MessageObject<Boolean> updateBatchById(@RequestBody List<T> entityList,
                                           @RequestParam("batchSize") int batchSize);

    @PostMapping(URL_PREFIX + "updateBatchById")
    MessageObject<Boolean> updateBatchById(@RequestBody List<T> entityList);


    /*******查*************查*****************查****************查****************查*************查************查*******/
    @GetMapping(URL_PREFIX + "getById")
    MessageObject<T> getById(@RequestParam("id") String id);

    @PostMapping(URL_PREFIX + "listByIds")
    MessageObject<List<T>> listByIds(@RequestBody List<String> idList);

    @PostMapping(URL_PREFIX + "listByMap")
    MessageObject<List<T>> listByMap(@RequestBody Map<String, Object> columnMap);

    @PostMapping(URL_PREFIX + "getOne")
    MessageObject<T> getOne(@RequestBody BaseDataQuerySqlWrapper<T> queryWrapper);

    @PostMapping(URL_PREFIX + "getMap")
    MessageObject<Map<String, Object>> getMap(@RequestBody BaseDataQuerySqlWrapper<T> queryWrapper);

    @PostMapping(URL_PREFIX + "countWrapper")
    MessageObject<Integer> count(@RequestBody BaseDataQuerySqlWrapper<T> queryWrapper);

    @GetMapping(URL_PREFIX + "count")
    MessageObject<Integer> count();

    @PostMapping(URL_PREFIX + "list")
    MessageObject<List<T>> list(@RequestBody BaseDataQuerySqlWrapper<T> queryWrapper);

    @GetMapping(URL_PREFIX + "listAll")
    MessageObject<List<T>> list();

    @PostMapping(URL_PREFIX + "pagePageWrapper")
    MessageObject<Page<T>> page(@RequestBody PageWrapper<T> pageWrapper);

    @PostMapping(URL_PREFIX + "page")
    MessageObject<Page<T>> page(@RequestBody Page<T> page);

    @PostMapping(URL_PREFIX + "pageQueryWrapper")
    MessageObject<Page<T>> page(@RequestBody BaseDataQuerySqlWrapper<T> querySqlWrapper);

    @PostMapping(URL_PREFIX + "pageMaps")
    MessageObject<Page<Map<String, Object>>> pageMaps(@RequestBody Page<T> page);

    @PostMapping(URL_PREFIX + "pageMapsWrapper")
    MessageObject<Page<Map<String, Object>>> pageMaps(@RequestBody PageWrapper<T> pageWrapper);

    @PostMapping(URL_PREFIX + "listMapsWrapper")
    MessageObject<List<Map<String, Object>>> listMaps(@RequestBody BaseDataQuerySqlWrapper<T> queryWrapper);

    @GetMapping(URL_PREFIX + "listMaps")
    MessageObject<List<Map<String, Object>>> listMaps();

}
